package corej.course.thread;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestActionEvent {
    public static void main(String[] args) {
        JFrame f = new JFrame("hehe");
        f.setSize(300, 100);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLayout(new FlowLayout());
        final JTextField jtf = new JTextField(20);
        JButton b = new JButton("OK");
        f.add(jtf);
        f.add(b);
        f.setVisible(true);

        class MyActionListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                System.out.println(jtf.getText());
            }
        }
        ActionListener al = new MyActionListener();
        jtf.addActionListener(al);
        b.addActionListener(al);

    }
}
